package org.example.ui.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.example.application.LoginService;
import org.example.domain.system.model.req.UserLoginReq;
import org.example.web.result.ResultInfo;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/api/auth/v1")
@Tag(name = "用户登录模块", description = "用户登录")
public class LoginController {
    private final LoginService loginService;

    @PostMapping("/login")
    @Operation(summary = "登录")
    public ResultInfo login(@Valid @RequestBody UserLoginReq userLoginReq) {
        return loginService.login(userLoginReq);
    }

    @DeleteMapping("/logout")
    @Operation(summary = "退出")
    public ResultInfo logout(HttpServletRequest request) {
        return loginService.logout(request);
    }

    @PostMapping("refresh")
    @Operation(summary = "刷新令牌有效期")
    public ResultInfo refresh(HttpServletRequest request) {
        return loginService.refresh(request);
    }

}
